package cn.sofwin.blog.servlet;

import cn.sofwin.blog.entity.Article;
import cn.sofwin.blog.service.ArticleService;
import cn.sofwin.blog.service.impl.ArticleServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/index")
public class IndexServlet extends HttpServlet {
    private ArticleService articleService= ArticleServiceImpl.getInstance();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //添加文章数据
        List<Article> articleList=articleService.all();
        req.setAttribute("articles",articleList);
        //跳转到首页jsp
        req.getRequestDispatcher("/main.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
